clearence and data preparation

rm(list = ls())
library(dendextend)
## 
## ---------------------
## Welcome to dendextend version 1.8.0
## Type citation('dendextend') for how to cite the package.
## 
## Type browseVignettes(package = 'dendextend') for the package vignette.
## The github page is: https://github.com/talgalili/dendextend/
## 
## Suggestions and bug-reports can be submitted at: https://github.com/talgalili/dendextend/issues
## Or contact: <tal.galili@gmail.com>
## 
##  To suppress this message use:  suppressPackageStartupMessages(library(dendextend))
## ---------------------
## 
## Attaching package: 'dendextend'
## The following object is masked from 'package:stats':
## 
##     cutree
#loading data
load('/home/mikhail/Telegram Desktop/matrix_2002.Rdata')

#exploring the data
str(dist_matrix_2002); class(dist_matrix_2002)
##  num [1:1273, 1:1273] 0 68727 49370 33879 24615 ...
## [1] "matrix"
#coercing to dist object
dist_2002 <- as.dist(dist_matrix_2002)

Heirarchical clusterization using all the methods available (“ward.D”, “ward.D2”, “single”, “complete”, “average” (= UPGMA), “mcquitty” (= WPGMA), “median” (= WPGMC) or “centroid”)

methods <- c("ward.D", "ward.D2", "single", "complete", "average", "mcquitty", "median", "centroid")
for (i in methods){
  for (j in methods){
    if (i == j){next} else {#no identical dendrograms comparison is needed
      hclusted_tmp1 <- hclust(dist_2002, method = i) 
      hclusted_tmp1 %>% as.dendrogram %>% set('labels_cex', 1e-9) -> dend_tmp1
      hclusted_tmp2 <- hclust(dist_2002, method = j) 
      hclusted_tmp2 %>% as.dendrogram %>% set('labels_cex', 1e-9) -> dend_tmp2
      ccc_tmp <- round(cor_cophenetic(dend_tmp1, dend_tmp2), digits = 2) 
      tanglegram(dend_tmp1, dend_tmp2, main_left = paste("2002 data\n ", i, "method"), main_right = paste("2002 data\n ", j, "method"), main = paste('CCC = ', ccc_tmp))
      #print(paste(i, j))
    } 
  }
}